﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.Infrastructure.Dto.Common;
using WCS.Infrastructure.Dto.Models.Order;
using WCS.Infrastructure.Dto.Request.Epaylinks;

namespace WCS.Infrastructure.Dto.Request.Order
{
    /// <summary>
    /// 订单表
    /// </summary>
    public class OrderRequestDto : BaseRequestDto
    {
        /// <summary>
        /// 订单ID
        /// </summary>
        [Key]
        [StringLength(32)]
        public string Id { get; set; } = null!;

        /// <summary>
        /// 订单编号
        /// </summary>
        [StringLength(32)]
        public string OrderCode { get; set; } = null!;

        /// <summary>
        /// 订单金额
        /// </summary>
        public long OrderAmount { get; set; } = 0;

        /// <summary>
        /// 订单类型
        /// </summary>
        public int OrderType { get; set; } = 0;

        /// <summary>
        /// 收款码ID
        /// </summary>
        [StringLength(32)]
        public string CodeId { get; set; } = null!;

        /// <summary>
        /// 门店ID
        /// </summary>
        [StringLength(32)]
        public string StoreId { get; set; } = null!;

        /// <summary>
        /// 商户ID
        /// </summary>
        [StringLength(32)]
        public string MerchantId { get; set; } = null!;

        /// <summary>
        /// 支付设备ID
        /// </summary>
        [StringLength(32)]
        public string? DeviceId { get; set; }

        /// <summary>
        /// 费率
        /// </summary>
        public decimal Rate { get; set; } = 0;

        /// <summary>
        /// 手续费
        /// </summary>
        public long Commission { get; set; } = 0;

        /// <summary>
        /// 优惠券实例ID
        /// </summary>
        [StringLength(32)]
        public string? CouponInstanceId { get; set; }

        /// <summary>
        /// 优惠金额
        /// </summary>
        public long? DiscountAmount { get; set; } = 0;

        /// <summary>
        /// 结算金额
        /// </summary>
        public long? SettlementAmount { get; set; } = 0;

        /// <summary>
        /// 平台服务费率（优惠券使用产生）
        /// </summary>
        public decimal? PlatformServiceFeeRate { get; set; } = 0;

        /// <summary>
        /// 平台服务费（优惠券使用产生）
        /// </summary>
        public long? PlatformServiceFee { get; set; } = 0;

        /// <summary>
        /// 支付时间
        /// </summary>
        [Column(TypeName = "timestamp(6) without time zone")]
        public DateTime? PaymentTime { get; set; }

        /// <summary>
        /// 支付状态(0=处理中，1=支付成功​，2=支付失败​​，3=已撤销，4=已关闭，5=已超时​​)
        /// </summary>
        public int PaymentStatus { get; set; } = 0;

        /// <summary>
        /// 优惠券推荐抽成金额
        /// </summary>
        public long? RecommendationCommissionAmount { get; set; } = 0;

        /// <summary>
        /// 推荐商户ID
        /// </summary>
        [StringLength(32)]
        public string? RecommendMerchantId { get; set; }

        /// <summary>
        /// 支付用户ID
        /// </summary>
        [StringLength(32)]
        public string? UserId { get; set; }

        /// <summary>
        /// 小程序OpenID
        /// </summary>
        [StringLength(32)]
        public string? OpenId { get; set; }

        /// <summary>
        /// 分账协议ID
        /// </summary>
        [StringLength(32)]
        public string? DividedAgreementId { get; set; }

        /// <summary>
        /// 订单快照
        /// </summary>
        [Column(TypeName = "jsonb")]
        public OrderSnapshotModel? OrderSnapshot { get; set; } = new OrderSnapshotModel();

        /// <summary>
        /// 累计退款金额
        /// </summary>
        public long? TotalRefundAmount { get; set; } = 0;

        /// <summary>
        /// 退款次数
        /// </summary>
        public int? RefundCount { get; set; } = 0;

        /// <summary>
        /// 退款状态(0=未退款,1=退款成功,2=退款失败​)
        /// </summary>
        public int RefundStatus { get; set; } = 0;

        /// <summary>
        /// 退款时间
        /// </summary>
        [Column(TypeName = "timestamp(6) without time zone")]
        public DateTime? RefundTime { get; set; }

        /// <summary>
        /// 最后退款时间
        /// </summary>
        [Column(TypeName = "timestamp(6) without time zone")]
        public DateTime? LastRefundTime { get; set; }

        /// <summary>
        /// 是否结算
        /// </summary>
        public int IsSettlement { get; set; }

        /// <summary>
        /// 结算日期(根据结算周期算出 只取日期部分 时间为 00:00:00)
        /// </summary>
        [Column(TypeName = "timestamp(0) without time zone")]
        public DateTime SettlementDate { get; set; }

        /// <summary>
        /// 结算时间
        /// </summary>
        [Column(TypeName = "timestamp(6) without time zone")]
        public DateTime? SettlementTime { get; set; }

        /// <summary>
        /// 是否分账
        /// </summary>
        public int IsDivided { get; set; }

        /// <summary>
        /// 分账日期(根据分账周期算出 只取日期部分 时间为 00:00:00)
        /// </summary>
        [Column(TypeName = "timestamp(0) without time zone")]
        public DateTime DividedDate { get; set; }

        /// <summary>
        /// 分账时间
        /// </summary>
        [Column(TypeName = "timestamp(6) without time zone")]
        public DateTime? DividedTime { get; set; }

        /// <summary>
        /// 版本号
        /// </summary>
        [StringLength(256)]
        public string? Version { get; set; }

        /// <summary>
        /// 商户订单号
        /// </summary>
        [StringLength(32)]
        public string OutTradeNo { get; set; } = null!;

        /// <summary>
        /// 商户编号
        /// </summary>
        [StringLength(32)]
        public string CustomerCode { get; set; } = null!;

        /// <summary>
        /// 用户终端 IP
        /// </summary>
        [StringLength(16)]
        public string? ClientIp { get; set; }

        /// <summary>
        /// 商品订单信息
        /// </summary>
        [Column(TypeName = "jsonb")]
        public EpaylinksOrderInfo? OrderInfo { get; set; } = new EpaylinksOrderInfo();

        /// <summary>
        /// 支付金额，单位为分
        /// </summary>
        public long PayAmount { get; set; } = 0;

        /// <summary>
        /// 支付币种：默讣CNY人民币 
        /// </summary>
        [StringLength(5)]
        public string PayCurrency { get; set; } = "CNY";

        /// <summary>
        /// 是否禁止信用卡支付
        /// </summary>
        [StringLength(5)]
        public string? NoCreditCards { get; set; }

        /// <summary>
        /// 支付结果通知地址
        /// </summary>
        [StringLength(256)]
        public string NotifyUrl { get; set; } = null!;

        /// <summary>
        /// 商户支付结果展示地址
        /// </summary>
        [StringLength(256)]
        public string? RedirectUrl { get; set; }

        /// <summary>
        /// 商户备注
        /// </summary>
        [StringLength(128)]
        public string? AttachData { get; set; }

        /// <summary>
        /// 交易开始时间
        /// </summary>
        [StringLength(14)]
        public string TransactionStartTime { get; set; } = null!;

        /// <summary>
        /// 交易超时时间
        /// </summary>
        [StringLength(14)]
        public string? TransactionEndTime { get; set; }

        /// <summary>
        /// 支付方式
        /// </summary>
        [StringLength(4)]
        public string? PayMethod { get; set; }

        /// <summary>
        /// 子商户公众号appid
        /// </summary>
        [StringLength(32)]
        public string? SubAppId { get; set; }

        /// <summary>
        /// 上游商户号
        /// </summary>
        [StringLength(32)]
        public string? ChannelMchtNo { get; set; }

        /// <summary>
        /// 分期可用渠道
        /// </summary>
        [StringLength(50)]
        public string? EnablePayChannels { get; set; }

        /// <summary>
        /// 分期期数
        /// </summary>
        public int? InstalmentsNum { get; set; }

        /// <summary>
        /// 支付宝门店编号
        /// </summary>
        [StringLength(32)]
        public string? AlipayStoreCode { get; set; }

        /// <summary>
        /// 支付宝门店ID
        /// </summary>
        [StringLength(32)]
        public string? AlipayStoreId { get; set; }

        /// <summary>
        /// 付款人信息（微信、支付宝支付时有效）
        /// </summary>
        [Column(TypeName = "jsonb")]
        public EpaylinksExtUserInfo? ExtUserInfo { get; set; }

        /// <summary>
        /// 终端信息
        /// </summary>
        [Column(TypeName = "jsonb")]
        public EpaylinksTerminalInfo? TerminalInfo { get; set; }

        /// <summary>
        /// 地区信息
        /// </summary>
        [StringLength(6)]
        public string AreaInfo { get; set; } = null!;

        /// <summary>
        /// 扩展参数
        /// </summary>
        [StringLength(256)]
        public string? ExtendParams { get; set; }

        /// <summary>
        /// 优惠编码
        /// </summary>
        [StringLength(50)]
        public string? Coupons { get; set; }

        /// <summary>
        /// 随机字符串
        /// </summary>
        [StringLength(32)]
        public string NonceStr { get; set; } = null!;

        /// <summary>
        /// 扩展属性
        /// </summary>
        public string? ExtraProperties { get; set; }

        /// <summary>
        /// 并发标记
        /// </summary>
        [StringLength(40)]
        public string? ConcurrencyStamp { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        [Column(TypeName = "timestamp(6) without time zone")]
        public DateTime CreationTime { get; set; }

        /// <summary>
        /// 创建人ID
        /// </summary>
        [StringLength(32)]
        public string? CreatorId { get; set; }

        /// <summary>
        /// 最后修改时间
        /// </summary>
        [Column(TypeName = "timestamp(6) without time zone")]
        public DateTime? LastModificationTime { get; set; }

        /// <summary>
        /// 最后修改者ID
        /// </summary>
        [StringLength(32)]
        public string? LastModifierId { get; set; }

        /// <summary>
        /// 是否删除
        /// </summary>
        public bool IsDeleted { get; set; }

        /// <summary>
        /// 删除者ID
        /// </summary>
        [StringLength(32)]
        public string? DeleterId { get; set; }

        /// <summary>
        /// 删除时间
        /// </summary>
        [Column(TypeName = "timestamp(6) without time zone")]
        public DateTime? DeletionTime { get; set; }

    }

}
